//
//  WDGoutReviewVehicleRemarkSingleImageView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/14.
//

#import "WDGoutReviewVehicleRemarkSingleImageView.h"
#import "TYZCommonCellModel.h"

@interface WDGoutReviewVehicleRemarkSingleImageView ()
@property (nonatomic, strong) TYZCommonCellModel *model;
@property (nonatomic, strong) UILabel *titleLabel;

//@property (nonatomic, strong) UIImageView *adImgView;
@property (nonatomic, strong) UIButton *adImgView;

/// 显示的图片
@property (nonatomic, strong) UIImageView *showImgView;

@end

@implementation WDGoutReviewVehicleRemarkSingleImageView

- (void)initWithSubView {
    
}

- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(0, self.height - 20, self.width, 20);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
        }];
    }
    if (self.model) {
        // *
        NSMutableAttributedString *mut = [EDSUtility attributeTitle:self.model.title titleColor:[UIColor colorWithHexString:@"#333333"] titleFont:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] value:@"*" valueColor:[UIColor redColor] valueFont:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium]];
        _titleLabel.attributedText = mut;
    }
}

- (void)initWithAdImgView {
    if (!_adImgView) {
        CGRect frame = CGRectMake(0, 0, self.width, self.height - self.titleLabel.height - 8);
        _adImgView = [UIButton createWithButton:self frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] target:self action:@selector(actionWithAdImage:) propertiesBlock:^(UIButton * _Nonnull button) {
            button.layer.cornerRadius = 5;
            button.layer.masksToBounds = YES;
            [button setImage:[UIImage imageNamed:self.model.iconImgName] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor colorWithHexString:@"#F6F9FD"];
            button.layer.borderColor = [UIColor colorWithHexString:@"#DFE1E9"].CGColor;
            button.layer.borderWidth = 1;
        }];
        
        UIImage *image = [UIImage imageNamed:@"ic_upload_camera_image"];
        CGRect cframe = CGRectMake((frame.size.width - image.size.width) * 0.5, (frame.size.height - image.size.height) * 0.5, image.size.width, image.size.height);
        UIImageView *cameraImgView = [UIImageView createWithImageView:_adImgView frame:cframe defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
//            imageView.userInteractionEnabled = ;
        }];
    }
}

- (void)initWithShowImgView {
    if (!_showImgView) {
        CGRect frame = self.adImgView.frame;
        _showImgView = [UIImageView createWithImageView:self frame:frame defaultImage:nil propertiesBlock:^(UIImageView * _Nonnull imageView) {
            imageView.layer.cornerRadius = 6;
            imageView.layer.masksToBounds = YES;
            imageView.userInteractionEnabled = YES;
            imageView.hidden = YES;
        }];
        
        UIImage *image = [UIImage imageNamed:@"cs_ic_delet_small"];
        CGRect btnFrame = CGRectMake(_showImgView.width - image.size.width, 0, image.size.width, image.size.height);
        UIButton *btnDel = [UIButton createWithButton:_showImgView frame:btnFrame font:FONTSIZE(15) target:self action:@selector(actionWithDelImage:) propertiesBlock:^(UIButton * _Nonnull button) {
            [button setImage:image forState:UIControlStateNormal];
        }];
    }
}

/// 点击删除图片
/// - Parameter sender: sender description
- (void)actionWithDelImage:(id)sender {
//    [SVProgressHUD showInfoWithStatus:@"ddd"];
    self.model.image = nil;
    self.model.url = nil;
    self.showImgView.hidden = YES;
    self.adImgView.hidden = NO;
    if (self.touchDelImageBlock) {
        self.touchDelImageBlock();
    }
}

/// 点击添加图片
/// - Parameter sender: sender description
- (void)actionWithAdImage:(id)sender {
    if (self.viewBlock) {
        self.viewBlock(self.model);
    }
}

- (void)updateWithImage:(UIImage *)image {
    _showImgView.image = image;
    _showImgView.hidden = NO;
    _adImgView.hidden = YES;
}

- (void)updateWithViewData:(id)data {
    self.model = data;
    
    [self initWithTitleLabel];
    
    [self initWithAdImgView];
    
    [self initWithShowImgView];
}



@end
